//TypeScript函数类型
type foo2 = (aa:number,bb?:number)=>number; //y = f(x)

let add:foo2 = function(a:number,b:number = 0):number
{
    return a+b;
} 

let subtra:foo2 =  function(a:number,b:number = 0):number
{
    return a-b;
} 

console.log(add(3,2),subtra(3,2));

let areaCircle:foo2 = function(a:number,b:number = Math.PI):number
{
    return Math.pow(a,2) * b;
} 

//计算圆的面积
console.log(areaCircle(5).toFixed(2));

//默认参数,针对对象如何实现可选值

class Animal1
{
  name:string;
  age:number;
  color?:string;
  
  constructor(name:string,age:number)
  {
        this.name = name;
        this.age = age;
  }
}

let cat = new Animal1("hanshi",18);

//任务1，构建一个班级的对象，
//包含班级名称,人数,楼层,负责人
//其中人数和负责人是可选，实例化一个班级对象，
// 并遍历输出对象的属性和名称
class ClassObj
{
    name:string;
    num?:number;
    addr:string;
    admin?:string;

    constructor(name:string,addr:string)
    {
        this.name = name;
        this.addr = addr;
    }

    static eat(food:string)
    {
      
        console.log(this.name +"吃"+food);
    }

    run=(addr:string)=>{
       console.log(this.name +"在"+ addr + "跑步");
    }

}

let aa = new ClassObj("AA班","1楼");
aa.num = 20;
aa.admin = "zhangsan";
//遍历输出对象的属性和名称
let entry = Object.entries(aa);
entry.forEach(e=>{
      let values =   Object.values(e);
      let pname = values[0];
      let value = values[1];
      console.log(`属性名:${pname} -> ${value}`);
})

ClassObj.eat("饭")
aa.run("操场")

//函数作为函数的参数
function fun(foo:Function,a:number,b:number)
{
   console.log(foo(a,b));
}

//fun(add,1,2);

